
package com.chongchong.auth.granter;

import com.chongchong.core.tool.api.R;
import com.chongchong.core.tool.utils.WebUtil;
import com.chongchong.user.entity.UserInfo;
import com.chongchong.user.feign.IUserClient;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 验证码TokenGranter
 *
 * @author
 */
@Component
@AllArgsConstructor
public class SSOGranter implements ITokenGranter {

	public static final String GRANT_TYPE = "sso";

	private IUserClient userClient;
	@Override
	public UserInfo grant(TokenParameter tokenParameter) {
		HttpServletRequest request = WebUtil.getRequest();

		String tenantId = tokenParameter.getArgs().getStr("tenantId");
		String account = tokenParameter.getArgs().getStr("account");
		UserInfo userInfo = null;
		// 获取用户类型
		String userType = tokenParameter.getArgs().getStr("userType");
		R<UserInfo> result = userClient.userInfo(tenantId, account);
		userInfo = result.isSuccess() ? result.getData() : null;
		return userInfo;
	}
}
